/*    */ package com.zimbra.cs.account.callback;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.AttributeCallback;
/*    */ import com.zimbra.cs.account.AttributeCallback.MultiValueMod;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ChildAccount
/*    */   extends AttributeCallback
/*    */ {
/*    */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*    */     throws ServiceException
/*    */   {
/* 43 */     if (context.isDoneAndSetIfNot(ChildAccount.class)) {
/* 44 */       return;
/*    */     }
/*    */     
/*    */ 
/*    */ 
/* 49 */     AttributeCallback.MultiValueMod visibleChildrenMod = multiValueMod(attrsToModify, "zimbraPrefChildVisibleAccount");
/* 50 */     AttributeCallback.MultiValueMod allChildrenMod = multiValueMod(attrsToModify, "zimbraChildAccount");
/*    */     
/* 52 */     Set<String> visibleChildren = newValuesToBe(visibleChildrenMod, entry, "zimbraPrefChildVisibleAccount");
/* 53 */     Set<String> allChildren = newValuesToBe(allChildrenMod, entry, "zimbraChildAccount");
/*    */     
/*    */ 
/* 56 */     if ((allChildren != null) && (!allChildren.contains(value))) {
/* 57 */       return;
/*    */     }
/*    */     
/* 60 */     if ((allChildrenMod != null) && (allChildrenMod.deleting())) {
/* 61 */       attrsToModify.put("zimbraPrefChildVisibleAccount", "");
/*    */     } else {
/* 63 */       Set<String> vidsToRemove = new HashSet();
/* 64 */       for (String vid : visibleChildren) {
/* 65 */         if (!allChildren.contains(vid))
/*    */         {
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 72 */           if ((allChildrenMod != null) && (allChildrenMod.removing()) && (visibleChildrenMod == null)) {
/* 73 */             vidsToRemove.add(vid);
/*    */           } else {
/* 75 */             throw ServiceException.INVALID_REQUEST("visible child id " + vid + " is not one of " + "zimbraChildAccount", null);
/*    */           }
/*    */         }
/*    */       }
/* 79 */       if (vidsToRemove.size() > 0)
/* 80 */         attrsToModify.put("-zimbraPrefChildVisibleAccount", vidsToRemove.toArray(new String[vidsToRemove.size()])); }
/*    */     Provisioning prov;
/*    */     Account parentAcct;
/*    */     String parentId;
/* 84 */     if ((entry instanceof Account)) {
/* 85 */       prov = Provisioning.getInstance();
/* 86 */       parentAcct = (Account)entry;
/* 87 */       parentId = parentAcct.getId();
/* 88 */       for (String childId : allChildren) {
/* 89 */         Account childAcct = prov.get(Key.AccountBy.id, childId);
/* 90 */         if (childAcct == null) {
/* 91 */           throw AccountServiceException.NO_SUCH_ACCOUNT(childId);
/*    */         }
/* 93 */         String[] children = childAcct.getChildAccount();
/* 94 */         for (String child : children) {
/* 95 */           if (child.equals(parentId)) {
/* 96 */             throw ServiceException.INVALID_REQUEST("child account " + childId + "(" + childAcct.getName() + ")" + " is parent of the parent account " + parentId + "(" + parentAcct.getName() + ")", null);
/*    */           }
/*    */         }
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/ChildAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */